﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CommonLib
{
    public class CommunicationInfo : MarshalByRefObject
    {
        public CommunicationInfo()
        {
        }
        public override object InitializeLifetimeService()
        {
            //////return base.InitializeLifetimeService();
            System.Runtime.Remoting.Lifetime.ILease aLease
                = (System.Runtime.Remoting.Lifetime.ILease)base.InitializeLifetimeService();

            if (aLease.CurrentState == System.Runtime.Remoting.Lifetime.LeaseState.Initial)
            {
                // 不过期
                aLease.InitialLeaseTime = TimeSpan.Zero;
            }
            return aLease;
        }
        /// <summary>
        /// 事件参数
        /// </summary>
        public class CommunicationEventArg : EventArgs
        {

            public string Message { get; set; }
        }
        /// <summary>
        /// 事件委托
        /// </summary>
        /// <param name="e"></param>
        public delegate void JobAddEventHandler(CommunicationEventArg e);
        /// <summary>
        /// 通知事件
        /// </summary>
        public event JobAddEventHandler OnJobAdd;
        /// <summary>
        /// 调用事件
        /// </summary>
        public void CallJobAddEvent(string msgSender)
        {
            OnJobAdd(new CommunicationEventArg() { Message = DateTime.Now.ToShortTimeString() + "\t" + msgSender + Environment.NewLine });
        }
    }
}
